function linear(t, b, s, d) {
    return s / d * t + b;
}

function animate(ele, target, duration=1000, fn) {
    if (ele.timer) {
        return;
    }
    var t = 0;
    var timeStep = 10;
    var begin = {};
    var change = {};
    var curPos = {};
    for(var attr in target){
        begin[attr] = utils.css(ele, attr);
        change[attr] = target[attr] - begin[attr];
    }

    ele.timer = setInterval(() => {
        // 1. 累加时间
        t += timeStep;
        // 2. 判断停止条件
        if (t >= duration) {
            clearInterval(ele.timer);
            // 设置目标位置
            utils.css(ele, target);
            ele.timer = null;
            fn && fn.apply(this,arguments);
            return;
        }
        // 3. 计算 t 时间 当前变化到的位置
        for (var attr in target) {
            curPos[attr] = linear(t, begin[attr], change[attr], duration);
        }
        utils.css(ele, curPos);
    }, timeStep);
}

